library(rdrobust)
library(foreign)
library(plyr)
library(ggplot2)
library(rdd)


#################
# RD Figure: MAIN EFFECTS - INDIVIDUAL LEVEL OUTCOMES
setwd("\\Users\\KKOSEC\\Dropbox (IFPRI)\\Ethio decentralisation\\Replication\\IFPRI_2008_09_Survey\\IFPRI_Individual_Level_Survey")

d <- read.table("Figure_5_Coefficients.txt",header=T)
d$pe <- d$c1
d$se <- d$c2
d$lb <- d$pe- 1.96*d$se
d$ub <- d$pe+ 1.96*d$se
d$group <- factor(d$c3,levels=c(10,9,8,7,6,5,4,3,2,1),
                  labels=c("Attended meeting to discuss agricultural issues","Attended district government-organized meeting to discuss ag. issues","Attended village government-organized meeting to discuss ag. issues","Meeting held in village to discuss agricultural issues","Visited a demonstration plot, home, or research station","Learned a new farming practice from district agent","Very satisfied with government-organized agri. meetings","Very satisfied with government-provided agri. inputs","Satisfied with water quality - wet season","Satisfied with water quality - dry season")[10:1])

f1 = ggplot(data = d, aes(x = group, y = pe, width=0.5,ymin = lb, ymax = ub))
f1 = f1 + geom_pointrange(size=0.5, position = position_dodge(width=.5))
f1 = f1 + scale_shape_manual(values=c(22,22))  
f1 = f1 + scale_fill_manual(values=c("black","black"))
f1 = f1 + coord_flip()
f1 = f1 + geom_hline(yintercept=0, linetype="longdash", size=0.5)
f1 = f1 + theme(axis.text=element_text(size=8), axis.title=element_text(size=10,face="bold"))
f1 = f1 + ylab("Effect of Decentralization with 95% C.I.") + xlab("Dependent Variable") 

f1 = f1+ theme(plot.background= element_rect(fill="grey100"),
               panel.background= element_rect(fill="grey100", color= "grey75"),
               panel.grid.major = element_line(color= "grey75"),
               panel.grid.minor = element_line(color= "grey80"),
               panel.grid.major.y = element_blank(),
               panel.grid.minor.y = element_blank(),
               panel.spacing.x = unit(12,"point"),
               axis.text = element_text(lineheight=0.5),
               legend.background = element_rect(fill="grey100")
)
print(f1)

